_connect.py: Don't request context when inspecting stack#2835
Merged
mxschmitt merged 6 commits intomicrosoft:mainfrom Apr 30, 2025
Merged
_connect.py: Don't request context when inspecting stack#2835mxschmitt merged 6 commits intomicrosoft:mainfrom
mxschmitt merged 6 commits intomicrosoft:mainfrom
Conversation
Contributor
Author
|
@microsoft-github-policy-service agree |
Contributor
Author
|
I have a feeling that this might noticeably improve the runtime of the test suite in |
Contributor
Author
|
Ready to have the workflows rerun :) |
This was referenced Apr 30, 2025
mxschmitt
approved these changes
Apr 30, 2025
Contributor
mxschmitt
left a comment
There was a problem hiding this comment.
Looks reasonable, thank you for the contribution!
Contributor
Author
|
Yay, thank you! :D |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR partially fixes #2744
This PR makes two changes:
inspect.stack(0)instead ofinspect.stack()inspect.stack()whengetattr(task, "__pw_stack__")doesn't find a stack in the taskinspect.stack()by default requests context for the first frame of the callstack, which is a very expensive operation. We don't use the returned context information, so we can safely useinspect.stack(context=0).In my testing, this improved the speed of
evaluate()by about 2.5x:Test:
Before this PR: 10s
After this PR: 4s
The second change is that we originally were calling
getattr(task, "__pw_stack__", inspect.stack()), which retrieved the entire callstack and then threw it away ifgetattr(task, "__pw_stack__")succeeded. I wasn't able to figure out how to getgetattr(task, "__pw_stack__")to return a value, so I'm not sure how much this change sped things up, but it seems like a sensible change to make.I've added async and sync tests.
I have a more detailed fix, but I figured I'd first try to get this PR landed, since it involves small changes for a pretty large speedup :)